﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using SaleManagement.Domains;
using SaleManagement.Data;

#endregion

namespace SaleManagement.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="GuaranteeProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class GuaranteeProviderBaseCore : EntityProviderBase<SaleManagement.Domains.Guarantee, SaleManagement.Domains.GuaranteeKey>
	{		
		#region Get from Many To Many Relationship Functions
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, SaleManagement.Domains.GuaranteeKey key)
		{
			return Delete(transactionManager, key.Id);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_id">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Int32 _id)
		{
			return Delete(null, _id);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_id">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Int32 _id);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblGuaranteeList key.
		///		FK_tblGuarantee_tblGuaranteeList Description: 
		/// </summary>
		/// <param name="_guanranteeListId"></param>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		public TList<Guarantee> GetByGuanranteeListId(System.Int32 _guanranteeListId)
		{
			int count = -1;
			return GetByGuanranteeListId(_guanranteeListId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblGuaranteeList key.
		///		FK_tblGuarantee_tblGuaranteeList Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_guanranteeListId"></param>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		/// <remarks></remarks>
		public TList<Guarantee> GetByGuanranteeListId(TransactionManager transactionManager, System.Int32 _guanranteeListId)
		{
			int count = -1;
			return GetByGuanranteeListId(transactionManager, _guanranteeListId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblGuaranteeList key.
		///		FK_tblGuarantee_tblGuaranteeList Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_guanranteeListId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		public TList<Guarantee> GetByGuanranteeListId(TransactionManager transactionManager, System.Int32 _guanranteeListId, int start, int pageLength)
		{
			int count = -1;
			return GetByGuanranteeListId(transactionManager, _guanranteeListId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblGuaranteeList key.
		///		fkTblGuaranteeTblGuaranteeList Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_guanranteeListId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		public TList<Guarantee> GetByGuanranteeListId(System.Int32 _guanranteeListId, int start, int pageLength)
		{
			int count =  -1;
			return GetByGuanranteeListId(null, _guanranteeListId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblGuaranteeList key.
		///		fkTblGuaranteeTblGuaranteeList Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_guanranteeListId"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		public TList<Guarantee> GetByGuanranteeListId(System.Int32 _guanranteeListId, int start, int pageLength,out int count)
		{
			return GetByGuanranteeListId(null, _guanranteeListId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblGuaranteeList key.
		///		FK_tblGuarantee_tblGuaranteeList Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_guanranteeListId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		public abstract TList<Guarantee> GetByGuanranteeListId(TransactionManager transactionManager, System.Int32 _guanranteeListId, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblHistoryPurchase key.
		///		FK_tblGuarantee_tblHistoryPurchase Description: 
		/// </summary>
		/// <param name="_historyPurchaseId"></param>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		public TList<Guarantee> GetByHistoryPurchaseId(System.Int32? _historyPurchaseId)
		{
			int count = -1;
			return GetByHistoryPurchaseId(_historyPurchaseId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblHistoryPurchase key.
		///		FK_tblGuarantee_tblHistoryPurchase Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_historyPurchaseId"></param>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		/// <remarks></remarks>
		public TList<Guarantee> GetByHistoryPurchaseId(TransactionManager transactionManager, System.Int32? _historyPurchaseId)
		{
			int count = -1;
			return GetByHistoryPurchaseId(transactionManager, _historyPurchaseId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblHistoryPurchase key.
		///		FK_tblGuarantee_tblHistoryPurchase Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_historyPurchaseId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		public TList<Guarantee> GetByHistoryPurchaseId(TransactionManager transactionManager, System.Int32? _historyPurchaseId, int start, int pageLength)
		{
			int count = -1;
			return GetByHistoryPurchaseId(transactionManager, _historyPurchaseId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblHistoryPurchase key.
		///		fkTblGuaranteeTblHistoryPurchase Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_historyPurchaseId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		public TList<Guarantee> GetByHistoryPurchaseId(System.Int32? _historyPurchaseId, int start, int pageLength)
		{
			int count =  -1;
			return GetByHistoryPurchaseId(null, _historyPurchaseId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblHistoryPurchase key.
		///		fkTblGuaranteeTblHistoryPurchase Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_historyPurchaseId"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		public TList<Guarantee> GetByHistoryPurchaseId(System.Int32? _historyPurchaseId, int start, int pageLength,out int count)
		{
			return GetByHistoryPurchaseId(null, _historyPurchaseId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblHistoryPurchase key.
		///		FK_tblGuarantee_tblHistoryPurchase Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_historyPurchaseId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		public abstract TList<Guarantee> GetByHistoryPurchaseId(TransactionManager transactionManager, System.Int32? _historyPurchaseId, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblPurchaseDetail key.
		///		FK_tblGuarantee_tblPurchaseDetail Description: 
		/// </summary>
		/// <param name="_purchaseDetailId"></param>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		public TList<Guarantee> GetByPurchaseDetailId(System.Int32? _purchaseDetailId)
		{
			int count = -1;
			return GetByPurchaseDetailId(_purchaseDetailId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblPurchaseDetail key.
		///		FK_tblGuarantee_tblPurchaseDetail Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_purchaseDetailId"></param>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		/// <remarks></remarks>
		public TList<Guarantee> GetByPurchaseDetailId(TransactionManager transactionManager, System.Int32? _purchaseDetailId)
		{
			int count = -1;
			return GetByPurchaseDetailId(transactionManager, _purchaseDetailId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblPurchaseDetail key.
		///		FK_tblGuarantee_tblPurchaseDetail Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_purchaseDetailId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		public TList<Guarantee> GetByPurchaseDetailId(TransactionManager transactionManager, System.Int32? _purchaseDetailId, int start, int pageLength)
		{
			int count = -1;
			return GetByPurchaseDetailId(transactionManager, _purchaseDetailId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblPurchaseDetail key.
		///		fkTblGuaranteeTblPurchaseDetail Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_purchaseDetailId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		public TList<Guarantee> GetByPurchaseDetailId(System.Int32? _purchaseDetailId, int start, int pageLength)
		{
			int count =  -1;
			return GetByPurchaseDetailId(null, _purchaseDetailId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblPurchaseDetail key.
		///		fkTblGuaranteeTblPurchaseDetail Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_purchaseDetailId"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		public TList<Guarantee> GetByPurchaseDetailId(System.Int32? _purchaseDetailId, int start, int pageLength,out int count)
		{
			return GetByPurchaseDetailId(null, _purchaseDetailId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblPurchaseDetail key.
		///		FK_tblGuarantee_tblPurchaseDetail Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_purchaseDetailId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		public abstract TList<Guarantee> GetByPurchaseDetailId(TransactionManager transactionManager, System.Int32? _purchaseDetailId, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblRepository key.
		///		FK_tblGuarantee_tblRepository Description: 
		/// </summary>
		/// <param name="_repositoryId"></param>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		public TList<Guarantee> GetByRepositoryId(System.Int32 _repositoryId)
		{
			int count = -1;
			return GetByRepositoryId(_repositoryId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblRepository key.
		///		FK_tblGuarantee_tblRepository Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_repositoryId"></param>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		/// <remarks></remarks>
		public TList<Guarantee> GetByRepositoryId(TransactionManager transactionManager, System.Int32 _repositoryId)
		{
			int count = -1;
			return GetByRepositoryId(transactionManager, _repositoryId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblRepository key.
		///		FK_tblGuarantee_tblRepository Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_repositoryId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		public TList<Guarantee> GetByRepositoryId(TransactionManager transactionManager, System.Int32 _repositoryId, int start, int pageLength)
		{
			int count = -1;
			return GetByRepositoryId(transactionManager, _repositoryId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblRepository key.
		///		fkTblGuaranteeTblRepository Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_repositoryId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		public TList<Guarantee> GetByRepositoryId(System.Int32 _repositoryId, int start, int pageLength)
		{
			int count =  -1;
			return GetByRepositoryId(null, _repositoryId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblRepository key.
		///		fkTblGuaranteeTblRepository Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_repositoryId"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		public TList<Guarantee> GetByRepositoryId(System.Int32 _repositoryId, int start, int pageLength,out int count)
		{
			return GetByRepositoryId(null, _repositoryId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblGuarantee_tblRepository key.
		///		FK_tblGuarantee_tblRepository Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_repositoryId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of SaleManagement.Domains.Guarantee objects.</returns>
		public abstract TList<Guarantee> GetByRepositoryId(TransactionManager transactionManager, System.Int32 _repositoryId, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override SaleManagement.Domains.Guarantee Get(TransactionManager transactionManager, SaleManagement.Domains.GuaranteeKey key, int start, int pageLength)
		{
			return GetById(transactionManager, key.Id, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_tblGuarantee index.
		/// </summary>
		/// <param name="_id"></param>
		/// <returns>Returns an instance of the <see cref="SaleManagement.Domains.Guarantee"/> class.</returns>
		public SaleManagement.Domains.Guarantee GetById(System.Int32 _id)
		{
			int count = -1;
			return GetById(null,_id, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblGuarantee index.
		/// </summary>
		/// <param name="_id"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="SaleManagement.Domains.Guarantee"/> class.</returns>
		public SaleManagement.Domains.Guarantee GetById(System.Int32 _id, int start, int pageLength)
		{
			int count = -1;
			return GetById(null, _id, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblGuarantee index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_id"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="SaleManagement.Domains.Guarantee"/> class.</returns>
		public SaleManagement.Domains.Guarantee GetById(TransactionManager transactionManager, System.Int32 _id)
		{
			int count = -1;
			return GetById(transactionManager, _id, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblGuarantee index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_id"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="SaleManagement.Domains.Guarantee"/> class.</returns>
		public SaleManagement.Domains.Guarantee GetById(TransactionManager transactionManager, System.Int32 _id, int start, int pageLength)
		{
			int count = -1;
			return GetById(transactionManager, _id, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblGuarantee index.
		/// </summary>
		/// <param name="_id"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="SaleManagement.Domains.Guarantee"/> class.</returns>
		public SaleManagement.Domains.Guarantee GetById(System.Int32 _id, int start, int pageLength, out int count)
		{
			return GetById(null, _id, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblGuarantee index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_id"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="SaleManagement.Domains.Guarantee"/> class.</returns>
		public abstract SaleManagement.Domains.Guarantee GetById(TransactionManager transactionManager, System.Int32 _id, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#region _tblGuarantee_GetReportByListId 
		
		/// <summary>
		///	This method wrap the '_tblGuarantee_GetReportByListId' stored procedure. 
		/// </summary>
		/// <param name="guaranteeListId"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetReportByListId(System.Int32? guaranteeListId)
		{
			return GetReportByListId(null, 0, int.MaxValue , guaranteeListId);
		}
		
		/// <summary>
		///	This method wrap the '_tblGuarantee_GetReportByListId' stored procedure. 
		/// </summary>
		/// <param name="guaranteeListId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetReportByListId(int start, int pageLength, System.Int32? guaranteeListId)
		{
			return GetReportByListId(null, start, pageLength , guaranteeListId);
		}
				
		/// <summary>
		///	This method wrap the '_tblGuarantee_GetReportByListId' stored procedure. 
		/// </summary>
		/// <param name="guaranteeListId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetReportByListId(TransactionManager transactionManager, System.Int32? guaranteeListId)
		{
			return GetReportByListId(transactionManager, 0, int.MaxValue , guaranteeListId);
		}
		
		/// <summary>
		///	This method wrap the '_tblGuarantee_GetReportByListId' stored procedure. 
		/// </summary>
		/// <param name="guaranteeListId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public abstract DataSet GetReportByListId(TransactionManager transactionManager, int start, int pageLength , System.Int32? guaranteeListId);
		
		#endregion
		
		#region _tblGuarantee_SearchByMachine 
		
		/// <summary>
		///	This method wrap the '_tblGuarantee_SearchByMachine' stored procedure. 
		/// </summary>
		/// <param name="customerCode"> A <c>System.String</c> instance.</param>
		/// <param name="customerName"> A <c>System.String</c> instance.</param>
		/// <param name="customerPhone"> A <c>System.String</c> instance.</param>
		/// <param name="machineCode"> A <c>System.String</c> instance.</param>
		/// <param name="fromDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="toDate"> A <c>System.DateTime?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet SearchByMachine(System.String customerCode, System.String customerName, System.String customerPhone, System.String machineCode, System.DateTime? fromDate, System.DateTime? toDate)
		{
			return SearchByMachine(null, 0, int.MaxValue , customerCode, customerName, customerPhone, machineCode, fromDate, toDate);
		}
		
		/// <summary>
		///	This method wrap the '_tblGuarantee_SearchByMachine' stored procedure. 
		/// </summary>
		/// <param name="customerCode"> A <c>System.String</c> instance.</param>
		/// <param name="customerName"> A <c>System.String</c> instance.</param>
		/// <param name="customerPhone"> A <c>System.String</c> instance.</param>
		/// <param name="machineCode"> A <c>System.String</c> instance.</param>
		/// <param name="fromDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="toDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet SearchByMachine(int start, int pageLength, System.String customerCode, System.String customerName, System.String customerPhone, System.String machineCode, System.DateTime? fromDate, System.DateTime? toDate)
		{
			return SearchByMachine(null, start, pageLength , customerCode, customerName, customerPhone, machineCode, fromDate, toDate);
		}
				
		/// <summary>
		///	This method wrap the '_tblGuarantee_SearchByMachine' stored procedure. 
		/// </summary>
		/// <param name="customerCode"> A <c>System.String</c> instance.</param>
		/// <param name="customerName"> A <c>System.String</c> instance.</param>
		/// <param name="customerPhone"> A <c>System.String</c> instance.</param>
		/// <param name="machineCode"> A <c>System.String</c> instance.</param>
		/// <param name="fromDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="toDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet SearchByMachine(TransactionManager transactionManager, System.String customerCode, System.String customerName, System.String customerPhone, System.String machineCode, System.DateTime? fromDate, System.DateTime? toDate)
		{
			return SearchByMachine(transactionManager, 0, int.MaxValue , customerCode, customerName, customerPhone, machineCode, fromDate, toDate);
		}
		
		/// <summary>
		///	This method wrap the '_tblGuarantee_SearchByMachine' stored procedure. 
		/// </summary>
		/// <param name="customerCode"> A <c>System.String</c> instance.</param>
		/// <param name="customerName"> A <c>System.String</c> instance.</param>
		/// <param name="customerPhone"> A <c>System.String</c> instance.</param>
		/// <param name="machineCode"> A <c>System.String</c> instance.</param>
		/// <param name="fromDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="toDate"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public abstract DataSet SearchByMachine(TransactionManager transactionManager, int start, int pageLength , System.String customerCode, System.String customerName, System.String customerPhone, System.String machineCode, System.DateTime? fromDate, System.DateTime? toDate);
		
		#endregion
		
		#region _tblGuarantee_SearchByGuanranteeListId 
		
		/// <summary>
		///	This method wrap the '_tblGuarantee_SearchByGuanranteeListId' stored procedure. 
		/// </summary>
		/// <param name="guaranteeListId"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet SearchByGuanranteeListId(System.Int32? guaranteeListId)
		{
			return SearchByGuanranteeListId(null, 0, int.MaxValue , guaranteeListId);
		}
		
		/// <summary>
		///	This method wrap the '_tblGuarantee_SearchByGuanranteeListId' stored procedure. 
		/// </summary>
		/// <param name="guaranteeListId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet SearchByGuanranteeListId(int start, int pageLength, System.Int32? guaranteeListId)
		{
			return SearchByGuanranteeListId(null, start, pageLength , guaranteeListId);
		}
				
		/// <summary>
		///	This method wrap the '_tblGuarantee_SearchByGuanranteeListId' stored procedure. 
		/// </summary>
		/// <param name="guaranteeListId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet SearchByGuanranteeListId(TransactionManager transactionManager, System.Int32? guaranteeListId)
		{
			return SearchByGuanranteeListId(transactionManager, 0, int.MaxValue , guaranteeListId);
		}
		
		/// <summary>
		///	This method wrap the '_tblGuarantee_SearchByGuanranteeListId' stored procedure. 
		/// </summary>
		/// <param name="guaranteeListId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public abstract DataSet SearchByGuanranteeListId(TransactionManager transactionManager, int start, int pageLength , System.Int32? guaranteeListId);
		
		#endregion
		
		#region _tblGuarantee_GetByCustomer 
		
		/// <summary>
		///	This method wrap the '_tblGuarantee_GetByCustomer' stored procedure. 
		/// </summary>
		/// <param name="customerId"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetByCustomer(System.Int32? customerId)
		{
			return GetByCustomer(null, 0, int.MaxValue , customerId);
		}
		
		/// <summary>
		///	This method wrap the '_tblGuarantee_GetByCustomer' stored procedure. 
		/// </summary>
		/// <param name="customerId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetByCustomer(int start, int pageLength, System.Int32? customerId)
		{
			return GetByCustomer(null, start, pageLength , customerId);
		}
				
		/// <summary>
		///	This method wrap the '_tblGuarantee_GetByCustomer' stored procedure. 
		/// </summary>
		/// <param name="customerId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetByCustomer(TransactionManager transactionManager, System.Int32? customerId)
		{
			return GetByCustomer(transactionManager, 0, int.MaxValue , customerId);
		}
		
		/// <summary>
		///	This method wrap the '_tblGuarantee_GetByCustomer' stored procedure. 
		/// </summary>
		/// <param name="customerId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public abstract DataSet GetByCustomer(TransactionManager transactionManager, int start, int pageLength , System.Int32? customerId);
		
		#endregion
		
		#region _tblGuarantee_GetByCode 
		
		/// <summary>
		///	This method wrap the '_tblGuarantee_GetByCode' stored procedure. 
		/// </summary>
		/// <param name="code"> A <c>System.String</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetByCode(System.String code)
		{
			return GetByCode(null, 0, int.MaxValue , code);
		}
		
		/// <summary>
		///	This method wrap the '_tblGuarantee_GetByCode' stored procedure. 
		/// </summary>
		/// <param name="code"> A <c>System.String</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetByCode(int start, int pageLength, System.String code)
		{
			return GetByCode(null, start, pageLength , code);
		}
				
		/// <summary>
		///	This method wrap the '_tblGuarantee_GetByCode' stored procedure. 
		/// </summary>
		/// <param name="code"> A <c>System.String</c> instance.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetByCode(TransactionManager transactionManager, System.String code)
		{
			return GetByCode(transactionManager, 0, int.MaxValue , code);
		}
		
		/// <summary>
		///	This method wrap the '_tblGuarantee_GetByCode' stored procedure. 
		/// </summary>
		/// <param name="code"> A <c>System.String</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public abstract DataSet GetByCode(TransactionManager transactionManager, int start, int pageLength , System.String code);
		
		#endregion
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;Guarantee&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;Guarantee&gt;"/></returns>
		public static TList<Guarantee> Fill(IDataReader reader, TList<Guarantee> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				SaleManagement.Domains.Guarantee c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("Guarantee")
					.Append("|").Append((System.Int32)reader[((int)GuaranteeColumn.Id - 1)]).ToString();
					c = EntityManager.LocateOrCreate<Guarantee>(
					key.ToString(), // EntityTrackingKey
					"Guarantee",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new SaleManagement.Domains.Guarantee();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.Id = (System.Int32)reader[((int)GuaranteeColumn.Id - 1)];
					c.Code = (reader.IsDBNull(((int)GuaranteeColumn.Code - 1)))?null:(System.String)reader[((int)GuaranteeColumn.Code - 1)];
					c.PurchaseDetailId = (reader.IsDBNull(((int)GuaranteeColumn.PurchaseDetailId - 1)))?null:(System.Int32?)reader[((int)GuaranteeColumn.PurchaseDetailId - 1)];
					c.HistoryPurchaseId = (reader.IsDBNull(((int)GuaranteeColumn.HistoryPurchaseId - 1)))?null:(System.Int32?)reader[((int)GuaranteeColumn.HistoryPurchaseId - 1)];
					c.RepositoryId = (System.Int32)reader[((int)GuaranteeColumn.RepositoryId - 1)];
					c.ReceiveDate = (System.DateTime)reader[((int)GuaranteeColumn.ReceiveDate - 1)];
					c.AttendReturn = (reader.IsDBNull(((int)GuaranteeColumn.AttendReturn - 1)))?null:(System.DateTime?)reader[((int)GuaranteeColumn.AttendReturn - 1)];
					c.ReturnDate = (reader.IsDBNull(((int)GuaranteeColumn.ReturnDate - 1)))?null:(System.DateTime?)reader[((int)GuaranteeColumn.ReturnDate - 1)];
					c.ChargeFee = (System.Int32)reader[((int)GuaranteeColumn.ChargeFee - 1)];
					c.Notes = (reader.IsDBNull(((int)GuaranteeColumn.Notes - 1)))?null:(System.String)reader[((int)GuaranteeColumn.Notes - 1)];
					c.GuanranteeListId = (System.Int32)reader[((int)GuaranteeColumn.GuanranteeListId - 1)];
					c.UpdatedDate = (reader.IsDBNull(((int)GuaranteeColumn.UpdatedDate - 1)))?null:(System.DateTime?)reader[((int)GuaranteeColumn.UpdatedDate - 1)];
					c.UpdatedBy = (reader.IsDBNull(((int)GuaranteeColumn.UpdatedBy - 1)))?null:(System.String)reader[((int)GuaranteeColumn.UpdatedBy - 1)];
					c.CreatedDate = (reader.IsDBNull(((int)GuaranteeColumn.CreatedDate - 1)))?null:(System.DateTime?)reader[((int)GuaranteeColumn.CreatedDate - 1)];
					c.CreatedBy = (reader.IsDBNull(((int)GuaranteeColumn.CreatedBy - 1)))?null:(System.String)reader[((int)GuaranteeColumn.CreatedBy - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="SaleManagement.Domains.Guarantee"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="SaleManagement.Domains.Guarantee"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, SaleManagement.Domains.Guarantee entity)
		{
			if (!reader.Read()) return;
			
			entity.Id = (System.Int32)reader[((int)GuaranteeColumn.Id - 1)];
			entity.Code = (reader.IsDBNull(((int)GuaranteeColumn.Code - 1)))?null:(System.String)reader[((int)GuaranteeColumn.Code - 1)];
			entity.PurchaseDetailId = (reader.IsDBNull(((int)GuaranteeColumn.PurchaseDetailId - 1)))?null:(System.Int32?)reader[((int)GuaranteeColumn.PurchaseDetailId - 1)];
			entity.HistoryPurchaseId = (reader.IsDBNull(((int)GuaranteeColumn.HistoryPurchaseId - 1)))?null:(System.Int32?)reader[((int)GuaranteeColumn.HistoryPurchaseId - 1)];
			entity.RepositoryId = (System.Int32)reader[((int)GuaranteeColumn.RepositoryId - 1)];
			entity.ReceiveDate = (System.DateTime)reader[((int)GuaranteeColumn.ReceiveDate - 1)];
			entity.AttendReturn = (reader.IsDBNull(((int)GuaranteeColumn.AttendReturn - 1)))?null:(System.DateTime?)reader[((int)GuaranteeColumn.AttendReturn - 1)];
			entity.ReturnDate = (reader.IsDBNull(((int)GuaranteeColumn.ReturnDate - 1)))?null:(System.DateTime?)reader[((int)GuaranteeColumn.ReturnDate - 1)];
			entity.ChargeFee = (System.Int32)reader[((int)GuaranteeColumn.ChargeFee - 1)];
			entity.Notes = (reader.IsDBNull(((int)GuaranteeColumn.Notes - 1)))?null:(System.String)reader[((int)GuaranteeColumn.Notes - 1)];
			entity.GuanranteeListId = (System.Int32)reader[((int)GuaranteeColumn.GuanranteeListId - 1)];
			entity.UpdatedDate = (reader.IsDBNull(((int)GuaranteeColumn.UpdatedDate - 1)))?null:(System.DateTime?)reader[((int)GuaranteeColumn.UpdatedDate - 1)];
			entity.UpdatedBy = (reader.IsDBNull(((int)GuaranteeColumn.UpdatedBy - 1)))?null:(System.String)reader[((int)GuaranteeColumn.UpdatedBy - 1)];
			entity.CreatedDate = (reader.IsDBNull(((int)GuaranteeColumn.CreatedDate - 1)))?null:(System.DateTime?)reader[((int)GuaranteeColumn.CreatedDate - 1)];
			entity.CreatedBy = (reader.IsDBNull(((int)GuaranteeColumn.CreatedBy - 1)))?null:(System.String)reader[((int)GuaranteeColumn.CreatedBy - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="SaleManagement.Domains.Guarantee"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="SaleManagement.Domains.Guarantee"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, SaleManagement.Domains.Guarantee entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.Id = (System.Int32)dataRow["Id"];
			entity.Code = Convert.IsDBNull(dataRow["Code"]) ? null : (System.String)dataRow["Code"];
			entity.PurchaseDetailId = Convert.IsDBNull(dataRow["PurchaseDetailId"]) ? null : (System.Int32?)dataRow["PurchaseDetailId"];
			entity.HistoryPurchaseId = Convert.IsDBNull(dataRow["HistoryPurchaseId"]) ? null : (System.Int32?)dataRow["HistoryPurchaseId"];
			entity.RepositoryId = (System.Int32)dataRow["RepositoryId"];
			entity.ReceiveDate = (System.DateTime)dataRow["ReceiveDate"];
			entity.AttendReturn = Convert.IsDBNull(dataRow["AttendReturn"]) ? null : (System.DateTime?)dataRow["AttendReturn"];
			entity.ReturnDate = Convert.IsDBNull(dataRow["ReturnDate"]) ? null : (System.DateTime?)dataRow["ReturnDate"];
			entity.ChargeFee = (System.Int32)dataRow["ChargeFee"];
			entity.Notes = Convert.IsDBNull(dataRow["Notes"]) ? null : (System.String)dataRow["Notes"];
			entity.GuanranteeListId = (System.Int32)dataRow["GuanranteeListId"];
			entity.UpdatedDate = Convert.IsDBNull(dataRow["UpdatedDate"]) ? null : (System.DateTime?)dataRow["UpdatedDate"];
			entity.UpdatedBy = Convert.IsDBNull(dataRow["UpdatedBy"]) ? null : (System.String)dataRow["UpdatedBy"];
			entity.CreatedDate = Convert.IsDBNull(dataRow["CreatedDate"]) ? null : (System.DateTime?)dataRow["CreatedDate"];
			entity.CreatedBy = Convert.IsDBNull(dataRow["CreatedBy"]) ? null : (System.String)dataRow["CreatedBy"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="SaleManagement.Domains.Guarantee"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">SaleManagement.Domains.Guarantee Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, SaleManagement.Domains.Guarantee entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region GuanranteeListIdSource	
			if (CanDeepLoad(entity, "GuaranteeList|GuanranteeListIdSource", deepLoadType, innerList) 
				&& entity.GuanranteeListIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.GuanranteeListId;
				GuaranteeList tmpEntity = EntityManager.LocateEntity<GuaranteeList>(EntityLocator.ConstructKeyFromPkItems(typeof(GuaranteeList), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.GuanranteeListIdSource = tmpEntity;
				else
					entity.GuanranteeListIdSource = DataRepository.GuaranteeListProvider.GetById(transactionManager, entity.GuanranteeListId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'GuanranteeListIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.GuanranteeListIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.GuaranteeListProvider.DeepLoad(transactionManager, entity.GuanranteeListIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion GuanranteeListIdSource

			#region HistoryPurchaseIdSource	
			if (CanDeepLoad(entity, "PreviousPurchase|HistoryPurchaseIdSource", deepLoadType, innerList) 
				&& entity.HistoryPurchaseIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = (entity.HistoryPurchaseId ?? (int)0);
				PreviousPurchase tmpEntity = EntityManager.LocateEntity<PreviousPurchase>(EntityLocator.ConstructKeyFromPkItems(typeof(PreviousPurchase), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.HistoryPurchaseIdSource = tmpEntity;
				else
					entity.HistoryPurchaseIdSource = DataRepository.PreviousPurchaseProvider.GetById(transactionManager, (entity.HistoryPurchaseId ?? (int)0));		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'HistoryPurchaseIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.HistoryPurchaseIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.PreviousPurchaseProvider.DeepLoad(transactionManager, entity.HistoryPurchaseIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion HistoryPurchaseIdSource

			#region PurchaseDetailIdSource	
			if (CanDeepLoad(entity, "PurchaseDetail|PurchaseDetailIdSource", deepLoadType, innerList) 
				&& entity.PurchaseDetailIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = (entity.PurchaseDetailId ?? (int)0);
				PurchaseDetail tmpEntity = EntityManager.LocateEntity<PurchaseDetail>(EntityLocator.ConstructKeyFromPkItems(typeof(PurchaseDetail), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.PurchaseDetailIdSource = tmpEntity;
				else
					entity.PurchaseDetailIdSource = DataRepository.PurchaseDetailProvider.GetById(transactionManager, (entity.PurchaseDetailId ?? (int)0));		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'PurchaseDetailIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.PurchaseDetailIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.PurchaseDetailProvider.DeepLoad(transactionManager, entity.PurchaseDetailIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion PurchaseDetailIdSource

			#region RepositoryIdSource	
			if (CanDeepLoad(entity, "Repository|RepositoryIdSource", deepLoadType, innerList) 
				&& entity.RepositoryIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.RepositoryId;
				Repository tmpEntity = EntityManager.LocateEntity<Repository>(EntityLocator.ConstructKeyFromPkItems(typeof(Repository), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.RepositoryIdSource = tmpEntity;
				else
					entity.RepositoryIdSource = DataRepository.RepositoryProvider.GetById(transactionManager, entity.RepositoryId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'RepositoryIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.RepositoryIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.RepositoryProvider.DeepLoad(transactionManager, entity.RepositoryIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion RepositoryIdSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the SaleManagement.Domains.Guarantee object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">SaleManagement.Domains.Guarantee instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">SaleManagement.Domains.Guarantee Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, SaleManagement.Domains.Guarantee entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region GuanranteeListIdSource
			if (CanDeepSave(entity, "GuaranteeList|GuanranteeListIdSource", deepSaveType, innerList) 
				&& entity.GuanranteeListIdSource != null)
			{
				DataRepository.GuaranteeListProvider.Save(transactionManager, entity.GuanranteeListIdSource);
				entity.GuanranteeListId = entity.GuanranteeListIdSource.Id;
			}
			#endregion 
			
			#region HistoryPurchaseIdSource
			if (CanDeepSave(entity, "PreviousPurchase|HistoryPurchaseIdSource", deepSaveType, innerList) 
				&& entity.HistoryPurchaseIdSource != null)
			{
				DataRepository.PreviousPurchaseProvider.Save(transactionManager, entity.HistoryPurchaseIdSource);
				entity.HistoryPurchaseId = entity.HistoryPurchaseIdSource.Id;
			}
			#endregion 
			
			#region PurchaseDetailIdSource
			if (CanDeepSave(entity, "PurchaseDetail|PurchaseDetailIdSource", deepSaveType, innerList) 
				&& entity.PurchaseDetailIdSource != null)
			{
				DataRepository.PurchaseDetailProvider.Save(transactionManager, entity.PurchaseDetailIdSource);
				entity.PurchaseDetailId = entity.PurchaseDetailIdSource.Id;
			}
			#endregion 
			
			#region RepositoryIdSource
			if (CanDeepSave(entity, "Repository|RepositoryIdSource", deepSaveType, innerList) 
				&& entity.RepositoryIdSource != null)
			{
				DataRepository.RepositoryProvider.Save(transactionManager, entity.RepositoryIdSource);
				entity.RepositoryId = entity.RepositoryIdSource.Id;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region GuaranteeChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>SaleManagement.Domains.Guarantee</c>
	///</summary>
	public enum GuaranteeChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>GuaranteeList</c> at GuanranteeListIdSource
		///</summary>
		[ChildEntityType(typeof(GuaranteeList))]
		GuaranteeList,
			
		///<summary>
		/// Composite Property for <c>PreviousPurchase</c> at HistoryPurchaseIdSource
		///</summary>
		[ChildEntityType(typeof(PreviousPurchase))]
		PreviousPurchase,
			
		///<summary>
		/// Composite Property for <c>PurchaseDetail</c> at PurchaseDetailIdSource
		///</summary>
		[ChildEntityType(typeof(PurchaseDetail))]
		PurchaseDetail,
			
		///<summary>
		/// Composite Property for <c>Repository</c> at RepositoryIdSource
		///</summary>
		[ChildEntityType(typeof(Repository))]
		Repository,
		}
	
	#endregion GuaranteeChildEntityTypes
	
	#region GuaranteeFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;GuaranteeColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Guarantee"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class GuaranteeFilterBuilder : SqlFilterBuilder<GuaranteeColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the GuaranteeFilterBuilder class.
		/// </summary>
		public GuaranteeFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the GuaranteeFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public GuaranteeFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the GuaranteeFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public GuaranteeFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion GuaranteeFilterBuilder
	
	#region GuaranteeParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;GuaranteeColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Guarantee"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class GuaranteeParameterBuilder : ParameterizedSqlFilterBuilder<GuaranteeColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the GuaranteeParameterBuilder class.
		/// </summary>
		public GuaranteeParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the GuaranteeParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public GuaranteeParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the GuaranteeParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public GuaranteeParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion GuaranteeParameterBuilder
	
	#region GuaranteeSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;GuaranteeColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Guarantee"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class GuaranteeSortBuilder : SqlSortBuilder<GuaranteeColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the GuaranteeSqlSortBuilder class.
		/// </summary>
		public GuaranteeSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion GuaranteeSortBuilder
	
} // end namespace
